<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of diag</title>
  <meta name="keywords" content="diag">
  <meta name="description" content="Extract the diagonal of the TT-matrix">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="#">tt2</a> &gt; <a href="index.html">@tt_matrix</a> &gt; diag.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for tt2/@tt_matrix&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>diag
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>Extract the diagonal of the TT-matrix</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [tt]=diag(tm) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">Extract the diagonal of the TT-matrix
   [TT]=DIAG(TM) Diagonal of the TT-matrix TM as a TT-tensor TT


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>	Converts TT-matrix to TT1 cell-array format</li><li><a href="../../tt2/@tt_tensor/core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>	Converts TT-tensor TT1 to old-cell array format.</li><li><a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>	Reshape of the TT-tensor</li><li><a href="../../tt2/@tt_tensor/tt_tensor.html" class="code" title="function t = tt_tensor(varargin)">tt_tensor</a>	TT-tensor constructor</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/@qtt_tucker/diag.html" class="code" title="function [qt]=diag(qt)">diag</a>	Diagonal of a matrix or diagonal matrix from a vector in QTT-Tucker</li><li><a href="../../tt2/@qtt_tucker/qtt_tucker.html" class="code" title="function t = qtt_tucker(varargin)">qtt_tucker</a>	QTT-Tucker contructor (TT-format for the core+QTT-format for the factors)</li><li><a href="../../tt2/@qtt_tucker/round.html" class="code" title="function [tt]=round(tt,varargin)">round</a>	Approximate QTT-Tucker with another one with specified accuracy</li><li><a href="mvk.html" class="code" title="function [y]=mvk(a,x,eps,nswp,z,rmax)">mvk</a>	DMRG fast matrix-by-vector product, Method 1 (less accurate)</li><li><a href="mvk2.html" class="code" title="function [y,swp]=mvk2(a,x,eps,nswp,z,rmax,varargin)">mvk2</a>	Two-sided DMRG fast matrix-by-vector product</li><li><a href="norm.html" class="code" title="function [nrm] = norm(t,varargin)">norm</a>	Matrix norm of the TT-matrix</li><li><a href="../../tt2/@tt_tensor/diag.html" class="code" title="function [tm]=diag(tt)">diag</a>	Constructs diagonal TT-matrix from TT-tensor</li><li><a href="../../tt2/@tt_tensor/funcrs.html" class="code" title="function [y]=funcrs(tt,fun,eps,y,nswp,varargin)">funcrs</a>	Cross approximation of a function of a TT-tensor, Method 1</li><li><a href="../../tt2/@tt_tensor/funcrs2.html" class="code" title="function [y]=funcrs2(tt,fun,eps,y,nswp)">funcrs2</a>	Cross approximation of a function of a TT-tensor, Method 2</li><li><a href="../../tt2/@tt_tensor/round.html" class="code" title="function [tt]=round(tt,varargin)">round</a>	Approximate TT-tensor with another one with specified accuracy</li><li><a href="../../tt2/@tt_tensor/sv.html" class="code" title="function [sval]=sv(tt)">sv</a>	Computes singular values of all unfoldings of a TT-tensor</li><li><a href="../../tt2/@tt_tensor/tt_tensor.html" class="code" title="function t = tt_tensor(varargin)">tt_tensor</a>	TT-tensor constructor</li><li><a href="../../tt2/core/move_tt_block.html" class="code" title="function [tt] = move_tt_block(tt, spos, epos, eps)">move_tt_block</a>	Performs a bubble movement of a block inside a train</li><li><a href="../../tt2/core/mvrk.html" class="code" title="function [y]=mvrk(A, x, eps, varargin)">mvrk</a>	Computes matvec in the QTT-Tucker "rake" format</li><li><a href="../../tt2/core/qtt_tucker_m.html" class="code" title="function [fc,core]=qtt_tucker_m(tt, sz, tol)">qtt_tucker_m</a>	Compute the QTT-Tucker representation of TT</li><li><a href="../../tt2/core/tt_compr2.html" class="code" title="function [tt] = tt_compr2(tt,eps, max_r)">tt_compr2</a>	Tensor rounding in TT1.0 format</li><li><a href="../../tt2/core/tt_mvk2.html" class="code" title="function [y,swp]=tt_mvk2(a,x,eps, max_r, max_swp)">tt_mvk2</a>	Matrix-by-vector product by DMRG/Krylov method</li><li><a href="../../tt2/core/tt_mvk3.html" class="code" title="function [y,swp]=tt_mvk3(W, x, eps, varargin)">tt_mvk3</a>	Two-sided DMRG fast matrix-by-vector product, the best version</li><li><a href="../../tt2/core/tt_reshape.html" class="code" title="function [tt2]=tt_reshape(tt1,sz,eps, rl, rr)">tt_reshape</a>	Reshape of the TT-tensor</li><li><a href="../../tt2/core/tt_tuck.html" class="code" title="function [factors,res]=tt_tuck(tt,eps)">tt_tuck</a>	Computes Tucker factors and Tucker core of the TT-tensor</li><li><a href="../../tt2/core/tt_wround.html" class="code" title="function [y,swp]=tt_wround(W, x, eps, varargin)">tt_wround</a>	Approximates a vector in the weighted norm using DMRG iterations</li><li><a href="../../tt2/cross/dmrg_cross.html" class="code" title="function [y]=dmrg_cross(d,n,fun,eps,varargin)">dmrg_cross</a>	DMRG-cross method for the approximation of TT-tensors</li><li><a href="../../tt2/cross/tt_rc.html" class="code" title="function [y]=tt_rc(d,n,elem_fun,eps,varargin)">tt_rc</a>	[Y]=TT_RC(D,N,ARR,ELEM_FUN,EPS,[OPTIONS])</li><li><a href="../../tt2/exp/Fd_mtx.html" class="code" title="function [M]=Fd_mtx(d, a, bound)">Fd_mtx</a>	Finite difference approximation of scalar diffusion equation in QTT</li><li><a href="../../tt2/exp/filters_wtt.html" class="code" title="function [wtt_transform] = filters_wtt (a,rmax,eps,sz)">filters_wtt</a>	Computes the WTT transform filters for a given tensor</li><li><a href="../../tt2/exp/lobpcg.html" class="code" title="function [blockVectorX,lambda,varargout] =lobpcg(blockVectorX,operatorA,varargin)">lobpcg</a>	LOBPCG solves Hermitian partial eigenproblems using preconditioning</li><li><a href="../../tt2/misc/tt_Fd_mtx1.html" class="code" title="function [M] = tt_Fd_mtx1(tt_a, bound1, bound2, eps)">tt_Fd_mtx1</a>	Generates finite-difference 1D matrix of \nabla(tt_a \nabla) in QTTM format.</li><li><a href="../../tt2/misc/tt_Fd_mtx2.html" class="code" title="function [ttm] = tt_Fd_mtx2(tt_a, bound1, bound2, eps)">tt_Fd_mtx2</a>	TT-representation of the diffusion matrix</li><li><a href="../../tt2/solve/dmrg_eigb.html" class="code" title="function [y,ev] = dmrg_eigb(a,k,eps,varargin)">dmrg_eigb</a>	Find several minimal eigenvalues of a TT-matrix using DMRG method</li><li><a href="../../tt2/solve/dmrg_rake_solve2.html" class="code" title="function [x]=dmrg_rake_solve2(A, y, tol, varargin)">dmrg_rake_solve2</a>	DMRG-type method for the solution of linear systems in QTT-Tucker format</li><li><a href="../../tt2/solve/dmrg_solve2.html" class="code" title="function [x, sweeps]=dmrg_solve2(A, y, eps,varargin)">dmrg_solve2</a>	Solution of linear systems in TT-format via DMRG iteration</li><li><a href="../../tt2/solve/tt_gmres.html" class="code" title="function [x,RESVEC,rw,rx] = tt_gmres(A, b, tol, maxout, maxin, eps_x, eps_z, M1, M2, M3, x0, verbose, varargin)">tt_gmres</a>	TT-GMRES method</li><li><a href="../../tt2/tests/test_full_KN2.html" class="code" title="">test_full_KN2</a>	The test script for the Crank-Nicolson scheme with global time stepping</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [tt]=diag(tm)</a>
0002 <span class="comment">%Extract the diagonal of the TT-matrix</span>
0003 <span class="comment">%   [TT]=DIAG(TM) Diagonal of the TT-matrix TM as a TT-tensor TT</span>
0004 <span class="comment">%</span>
0005 <span class="comment">%</span>
0006 <span class="comment">% TT-Toolbox 2.2, 2009-2012</span>
0007 <span class="comment">%</span>
0008 <span class="comment">%This is TT Toolbox, written by Ivan Oseledets et al.</span>
0009 <span class="comment">%Institute of Numerical Mathematics, Moscow, Russia</span>
0010 <span class="comment">%webpage: http://spring.inm.ras.ru/osel</span>
0011 <span class="comment">%</span>
0012 <span class="comment">%For all questions, bugs and suggestions please mail</span>
0013 <span class="comment">%ivan.oseledets@gmail.com</span>
0014 <span class="comment">%---------------------------</span>
0015 tt=<a href="../../tt2/@tt_tensor/tt_tensor.html" class="code" title="function t = tt_tensor(varargin)">tt_tensor</a>;
0016 n=tm.n;
0017 tt1=tm.tt;
0018 r=tt1.r;
0019 <a href="core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>=tt1.core;
0020 ps=tt1.ps;
0021 d=tt1.d;
0022 ps1=cumsum([1;n.*r(1:d).*r(2:d+1)]);
0023 core1=zeros(ps1(d+1)-1,1);
0024 <span class="keyword">for</span> i=1:d
0025    cur_core=<a href="core.html" class="code" title="function [tt] = core(tt1,varargin)">core</a>(ps(i):ps(i+1)-1);cur_core=<a href="../../tt2/@tt_tensor/reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(cur_core,[r(i),n(i),n(i),r(i+1)]);
0026    cur_core1=zeros(r(i),n(i),r(i+1));
0027    <span class="keyword">for</span> j=1:n(i)
0028       cur_core1(:,j,:)=cur_core(:,j,j,:);
0029    <span class="keyword">end</span>
0030    core1(ps1(i):ps1(i+1)-1)=cur_core1(:);
0031 <span class="keyword">end</span>
0032 tt.r=r;
0033 tt.n=n;
0034 tt.core=core1;
0035 tt.ps=ps1;
0036 tt.d=d;
0037 <span class="keyword">return</span>
0038 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Wed 08-Feb-2012 18:20:24 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>